#!/bin/bash

if ! command -v tmux >/dev/null 2>&1; then
    echo "tmux not found"
    exit 1
fi

[[ -f ./build/cc ]] || (
    echo "[-] Building CC server as it's not found"
    python3 ./build.py cc
)

(
    tmux source-file ./tmux/.tmux.conf
    cp -r ./tmux/sh /tmp
    cd build || {
        echo "./build doesn't exist"
        exit 1
    }

    if [ -n "$TMUX" ]; then
        tmux rename-session emp3r0r
        tmux rename-window cc
        ./cc "$@"
    else
        tmux new-session -s emp3r0r ./cc "$@" || tmux attach -t emp3r0r
    fi
)
